﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace View
{
    public partial class Customer : Form
    {
        private Menu menu;
        public Customer(Menu menu)
        {
            this.menu = menu;
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
               Convert.ToInt64(textBox1.Text);
            }
            catch (FormatException)
            {
                textBox1.Text = "הכנס מספר";
                return;
            }
            if (textBox1.Text.Length != 10)
            {
                textBox1.Text = "הכנס מספר בן 10 ספרות";
                return;
            }

            string phone = textBox1.Text;
            Controller.Customer customer = new Controller.Customer(phone);
            if(customer.exist())
            {
                Orders x = new Orders(menu, phone, customer.getMyName());
                x.Show();
            }
            else
            {
                CustomerDetails x = new CustomerDetails(phone,menu);
                x.Show();
            }
            this.Dispose();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            menu.Show();
            this.Dispose();
        }

        private void Customer_Load(object sender, EventArgs e)
        {

        }
    }
}
